Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection

Namespace CEL.Modules.CELLibrary
    Partial Class BorrowBook
        Inherits Entities.Modules.PortalModuleBase

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Page.IsPostBack = True Then Exit Sub
            ViewState("AllowPaging") = "False"
            Me.lnkShow.Text = "Show 10 records per page"
            Call loadBorrowedGrid()
        End Sub

        Public Sub loadBorrowedGrid()
            Dim objLibraryCon As New CELLibraryController
            Dim dtTable As DataTable = objLibraryCon.GetAllBorrowedBook(ModuleId)
            If Convert.ToString(ViewState("AllowPaging")) = "True" Then
                Me.dgViewBorrowed.AllowPaging = True
                Me.dgViewBorrowed.PageSize = 10

            Else
                Me.dgViewBorrowed.AllowPaging = False
            End If
            Me.dgViewBorrowed.DataSource = dtTable
            Me.dgViewBorrowed.DataBind()
        End Sub
        Public Function getBorrowedByname(ByVal OwnerID As Integer) As String
            Dim objUserCon As New UserController
            Dim objUserInfo As UserInfo = objUserCon.GetUser(PortalId, OwnerID)
            If Not objUserInfo Is Nothing Then Return objUserInfo.Username
            Return ""
        End Function

        Protected Sub dgViewBorrowed_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgViewBorrowed.ItemCommand
            If e.CommandName = "Remove" Then
                Dim objLibraryCon As New CELLibraryController
                Dim LibraryID As Label = CType(e.Item.FindControl("lblLibraryID"), Label)
                objLibraryCon.RemoveBorrow(Val(e.CommandArgument), Val(LibraryID.Text))
                Call loadBorrowedGrid()
            End If
        End Sub
        Protected Sub dgViewBorrowed_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgViewBorrowed.ItemDataBound
            If e.Item.ItemType = ListItemType.Header Or e.Item.ItemType = ListItemType.Footer Then
            Else
                e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#ffffcc'")
                e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#eeeeee'")

                Dim lnkRemove As LinkButton = CType(e.Item.FindControl("lnkRemove"), LinkButton)
                lnkRemove.Attributes.Add("onclick", "return confirm('Confirm remove from borrowed list');")
            End If
        End Sub

        Protected Sub lnkBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBack.Click
            Response.Redirect(EditUrl("ManageBooks"), True)
        End Sub

        Protected Sub lnkShow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkShow.Click
            If Me.lnkShow.Text = "Show 10 records per page" Then
                ViewState("AllowPaging") = "True"
                'ViewState("PagingSize") = "10"
                Me.lnkShow.Text = "Show all records"
            ElseIf Me.lnkShow.Text = "Show all records" Then
                ViewState("AllowPaging") = "False"
                Me.lnkShow.Text = "Show 10 records per page"
            End If
            Call loadBorrowedGrid()
        End Sub
    End Class
End Namespace